package main

import "fmt"

type Speaker interface {
	Speaker() string
}

type Person struct {
	Name string
}

func (p Person) Speaker() string {
	return "i am " + p.Name
}

type Speaker interface {
	Speak() string
}

type Person struct {
	Name string
}

func (p Person) Speak() string {
	return "Hello, my name is " + p.Name
}

func introduce(s Speaker) {
	fmt.Println(s.Speak())
}

func printString(x interface{}) {
	if str, ok := x.(string); ok {
		fmt.Println("String:", str)
	} else {
		fmt.Println("Not a string")
	}
}

func tset() {
	var s Speaker
	fmt.Println(s == nil) // 输出 true

	var x interface{}
	fmt.Println(x == nil) // 输出 true
}

func main() {
	p := Person{Name: "Alice"}

	// 使用接口变量来存储 Person 类型的值
	introduce(p) // 输出: Hello, my name is Alice

	// 空接口
	var x interface{} = 42
	fmt.Println(x) // 输出 42

	x = "Hello, Go!"
	fmt.Println(x) // 输出 Hello, Go!

	printString("Hello") // 输出 String: Hello
	printString(42)      // 输出 Not a string
}

type Speaker interface {
	Speak() string
}

type Person struct {
	Name string
}

func (p Person) Speak() string {
	return "Hello, my name is " + p.Name
}

type Dog struct {
	Name string
}

func (d Dog) Speak() string {
	return "Woof, my name is " + d.Name
}

func greet(s Speaker) {
	fmt.Println(s.Speak())
}

func main2() {
	p := Person{Name: "Alice"}
	d := Dog{Name: "Rex"}

	greet(p) // 输出: Hello, my name is Alice
	greet(d) // 输出: Woof, my name is Rex
}
